package com.guigu.wenzhiyi.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.tankai.mapper.MemberMapper;
import com.guigu.tankai.mapper.UserMapper;
import com.guigu.tankai.pojo.Member;
import com.guigu.tankai.pojo.User;
import com.guigu.wenzhiyi.mapper.InterposefollowupvisitMapper;
import com.guigu.wenzhiyi.pojo.Interposefollowupvisit;
import com.guigu.wenzhiyi.service.InterposefollowupvisitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InterposefollowupvisitServiceImpl implements InterposefollowupvisitService {

    @Autowired
    InterposefollowupvisitMapper interposefollowupvisitMapper;
    @Autowired
    MemberMapper memberMapper;
    @Autowired
    UserMapper userMapper;


    @Override
    public PageInfo<Interposefollowupvisit> page(Integer num, Integer size, String name) {
        PageHelper.startPage(num,size);
        List<Interposefollowupvisit> list = interposefollowupvisitMapper.page(name);
        for (Interposefollowupvisit interposefollowupvisit : list) {
            User user = userMapper.selectByPrimaryKey(interposefollowupvisit.getHealthmgrid());
            interposefollowupvisit.setUser(user);
        }
        return new PageInfo<>(list);
    }

    @Override
    public List<Member> cha(String name) {
        return memberMapper.MemberCha(name);
    }

    @Override
    public int add(Interposefollowupvisit interposefollowupvisit) {
        int id = memberMapper.chaID(interposefollowupvisit.getFilenumber());
        Member member = new Member();
        member.setId(id);
        member.setFollowupvisitzt(1);
        memberMapper.zt(member);
        return interposefollowupvisitMapper.insert(interposefollowupvisit);
    }

    @Override
    public int update(Interposefollowupvisit interposefollowupvisit) {
        return interposefollowupvisitMapper.updateByPrimaryKeySelective(interposefollowupvisit);
    }

    @Override
    public int delete(Integer id) {
        return interposefollowupvisitMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Interposefollowupvisit> puisit() {
        return interposefollowupvisitMapper.puisit();
    }

}
